<html>

<head>
    <script>
        var dojoConfig = {
            paths: {
                "olesk": "/olesk"
            }
        };
    </script>

    <script type="text/javascript"
            src="/dj/dojo/dojo.js"
		    data-dojo-config="isDebug:true">
    </script>

    <script type="text/javascript">

        require(["doh",
                 "require",
                 "dojo/query",
                 "dojo/dom-class",
                 "dojo/dom",
                 "dojo/dom-construct",
                 "dojo/on",
                 "dojo/mouse",
                 "dojo/_base/lang",
                 "dojo/NodeList-dom",
                 "dojo/robotx",
                 "dojo/domReady!"], function (doh, require, query, domClass, dom, domConstruct, on, mouse, lang) {

            doh.robot.initRobot('./test_carousel.html');
            
            var base_test_object_factory = function () {

                return {

                    setUp: function () {
                            // Remove widget node from the DOM.
                            // Each further test should clone widget node, 
                            // inset it before test and remove after.
                            this.widgetElem = query("#arena").orphan()[0];
                            domConstruct.place(lang.clone(this.widgetElem), "vertical_carousel");
                            // ! events attached to DOM element are not cloned !
                            window.init_carousel();
                    },
                    tearDown: function () {
                            domConstruct.empty("vertical_carousel");
                            domConstruct.place(this.widgetElem, "vertical_carousel");
                    }
                };
            };
                        
            doh.register("buttons", [
                
                lang.mixin(base_test_object_factory(), {

                    name: "buttons initial classes",
                    runTest: function() {
						var d = new doh.Deferred();
                        
                        var fwrd_button = query(".button.frwd")[0];
                        var bwrd_button = query(".button.brwd")[0];
                        
                        on.once(fwrd_button, mouse.enter, d.getTestCallback(function () {
                                doh.t(domClass.contains(fwrd_button, "active"));
                                doh.f(domClass.contains(bwrd_button, "active"));
					    }));
						
						doh.robot.mouseMoveAt(fwrd_button, 500, 500);

                        return d;
					},
                    timeout: 4000
                }),
                lang.mixin(base_test_object_factory(), {

                    name: "forward button first click",
                    runTest: function() {
						var d = new doh.Deferred();

                        var fwrd_button = query(".button.frwd")[0];
                        var bwrd_button = query(".button.brwd")[0];

                        doh.robot.mouseMoveAt(fwrd_button, 500, 500);
                        doh.robot.mouseClick({left:true}, 100);

                        doh.robot.sequence(d.getTestCallback(function () {
							doh.t(domClass.contains(fwrd_button, "active"));
                            doh.t(domClass.contains(bwrd_button, "active"));
						}), 2000);

                        return d;
					},
                    timeout: 4000
                }),
                lang.mixin(base_test_object_factory(), {

                    name: "forward button in the end state",
                    runTest: function() {
						var d = new doh.Deferred();

                        var fwrd_button = query(".button.frwd")[0];
                        var bwrd_button = query(".button.brwd")[0];

                        doh.robot.mouseMoveAt(fwrd_button, 500, 500);
                        doh.robot.mouseClick({left:true}, 1000);
                        doh.robot.mouseClick({left:true}, 1000);
                        doh.robot.mouseClick({left:true}, 1000);
                        doh.robot.mouseClick({left:true}, 1000);

                        doh.robot.sequence(d.getTestCallback(function () {
							doh.f(domClass.contains(fwrd_button, "active"));
                            doh.t(domClass.contains(bwrd_button, "active"));
						}), 2000);

                        return d;
					},
                    timeout: 10000
                })
            ]);

            doh.register("items", [

                lang.mixin(base_test_object_factory(), {

                    name: "items initial classes",
                    runTest: function() {
						var d = new doh.Deferred();

                        setTimeout(d.getTestCallback(function () {
                            doh.assertEqual(1, query(".item.current").length);
                            doh.t(domClass.contains(query(".item")[0], "current"));
                        }), 100);

						return d;
					},
                    timeout: 4000
                }),
                lang.mixin(base_test_object_factory(), {

                    name: "move tape one step forward",
                    runTest: function() {
						var d = new doh.Deferred();

                        var fwrd_button = query(".button.frwd")[0];
                                                
                        doh.robot.mouseMoveAt(fwrd_button, 500, 500);
                        doh.robot.mouseClick({left:true}, 100)

                        doh.robot.sequence(d.getTestCallback(function () {
								doh.assertEqual(1, query(".item.current").length);
                                doh.t(domClass.contains(query(".item")[1], "current"));
						}), 500);

						return d;
					},
                    timeout: 4000
                }),
                lang.mixin(base_test_object_factory(), {

                    name: "click during transition are ignored",
                    runTest: function() {
						var d = new doh.Deferred();

                        var fwrd_button = query(".button.frwd")[0];
                        var bwrd_button = query(".button.brwd")[0];
                        
                        doh.robot.mouseMoveAt(fwrd_button, 500, 500);
                        doh.robot.mouseClick({left:true}, 5);
                        doh.robot.mouseClick({left:true}, 5);
                        doh.robot.mouseClick({left:true}, 5);
                        
                        doh.robot.sequence(d.getTestCallback(function () {
                            doh.assertEqual(1, query(".item.current").length);
                            doh.t(domClass.contains(query(".item")[1], "current"));
							doh.t(domClass.contains(fwrd_button, "active"));
                            doh.t(domClass.contains(bwrd_button, "active"));
						}), 2000);

                        return d;
					},
                    timeout: 10000
                })
            ]);

            doh.run();
           
        });
    </script>
</head>
</html>
